package team1.project2.metrics.testcases;

import static org.junit.Assert.assertNotNull;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class MetricsServiceTest {
	
	URL url;
	HttpURLConnection conn;
	String output;
	
	@Before
	 public void noSetup() throws MalformedURLException {
		url = new URL("http://localhost/MetricsService/get/metrics");
	 }
	 
	 @After
	 public void noTearDown() {
		 conn.disconnect();
		 
	 }
	 
	 @Test
	 public void pushTest() {
	   
		 try {
				conn = (HttpURLConnection) url.openConnection();
				conn.setRequestMethod("GET");
				conn.setRequestProperty("Accept", "application/json");
		 
				if (conn.getResponseCode() != 200) {
					throw new RuntimeException("Failed : HTTP error code : "
							+ conn.getResponseCode());
				}
		 
				BufferedReader br = new BufferedReader(new InputStreamReader(
					(conn.getInputStream())));
				System.out.println("Output from Server .... \n");
				while ((output = br.readLine()) != null) {
					System.out.println(output);

				}
				assertNotNull(output);
			  } catch (MalformedURLException e) {		 
				e.printStackTrace();		 
			  } catch (IOException e) {		 
				e.printStackTrace();		 
			  }	 
	 }
}
